<?php
if (!defined('CURRENT_PATH')){
	die('Hacking attempt');
	}
if($_REQUEST['act']&&$_REQUEST['act']=='save'){
if($this->spArgs(User)!=null&&$this->spArgs(Name)!=null&&$this->spArgs(Pass)==$this->spArgs(RePass)&&strlen($this->spArgs(Pass))>=6){
	$adminedit=spClass(manage);
	$saveMapArr=array('User'=>'username','Name'=>'name','Pass'=>'password',);
	//检查用户名是否存在
	$res=$adminedit->find($conditions=array('username'=>$this->spArgs(User)),'',$fields='1');
	if($res){
		$msg='该用户名已经存在！';
		$this->error($msg);
		die;
	}else{	
	//dump($this->spArgs());	
		$newrow=array(id=>'',auth =>'0',);
		foreach($saveMapArr as $id=>$v){
			$tempArr=array($v=>$this->spArgs($id));
			$newrow=array_merge($newrow,$tempArr);
		}
		import(CURRENT_PATH.'/lib/class-phpass.php');
		$passwordValue = $newrow['password'];  
		/*------------密码生成---------------*/
		$hasher = new PasswordHash(8, TRUE);  
		$sigPassword = $hasher->HashPassword($passwordValue);
		$newrow['password']=$sigPassword ;
		/*-----------------------------------*/
		mysql_query("set sql_mode=''");
		$adminedit->create($newrow);
		$this->success('添加管理员成功！','');		
	}
	}else{
		if($this->spArgs(User)==null||$this->spArgs(Name)==null){
			$msg='用户名及姓名不得为空！';
		}else if(strlen($this->spArgs(Pass))<6){
			$msg='密码长度不得小于六位';
		}else if($this->spArgs(Pass)!=$this->spArgs(RePass)){
			$msg='两次输入密码不同';
		}
		$this->error($msg);
	}		
}else{
 $this->display('management/adminadd.html');	
}